//角色管理API
import { request } from '@/utils/request'
import type { UserResponseData, User, RoleResponseData } from './type'
enum API {
  ALLUSER_URL = '/admin/acl/user/',
  ADDUSER_URL = '/admin/acl/user/save',
  UPDATEUSER_URL = '/admin/acl/user/update',
  REMOVEUSER_URL = '/admin/acl/user/remove/',
  REMOVEUSERLIST_URL = '/admin/acl/user/batchRemove',
  //根据用户获取角色
  ALLROLEURL = '/admin/acl/user/toAssign/{userId}',
}
//获取全部已有用户信息
export const reqUserinfo = (page: number, limit: number, username: string) =>
  request.get<any, UserResponseData>(API.ALLUSER_URL + `${page}/${limit}/?username=${username}`)
//添加和更新用户
export const reqAddUserOrUpdataUser = (user: User) => {
  if (user.id) {
    return request.put<any, any>(API.UPDATEUSER_URL, user)
  } else {
    return request.post<any, any>(API.ADDUSER_URL, user)
  }
}
//删除用户接口
export const reqRemoveUser = (userid: string) =>
  request.delete<any, any>(API.REMOVEUSER_URL + userid)
//批量删除用户接口
export const reqRemoveList = (idlist: number[]) =>
  request.delete<any, any>(API.REMOVEUSERLIST_URL, { data: idlist })
//根据用户获取角色
export const reqAllRole = (userId: number) =>
  request.get<any, RoleResponseData>(API.ALLROLEURL + userId)
